package com.psbc;

import java.sql.*;

public class TestPgsql {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //加载驱动
        Class.forName("org.postgresql.Driver");
        String url = "jdbc:postgresql://localhost:5432/postgres";
        String user = "postgres";
        String password = "112233";//写自己之前设置的
        //建立连接
        Connection conn = null;
        Statement stmt = null;
        conn = DriverManager.getConnection(url, user, password);
        stmt = conn.createStatement();
        //编译和执行SQL语句
        String sql = "select * from student";
        ResultSet rs = stmt.executeQuery(sql);
        while (rs.next()) {
            System.out.println("id=" + rs.getObject("id"));
            System.out.println("name=" + rs.getObject("name"));
        }
        //释放连接
        rs.close();
        stmt.close();
        conn.close();
    }
}
